<?php
/**
 * DwzActiveForm class file.
 *
 * @author biner <huanghuibin@gmail.com>
 * @license http://www.yiiframework.com/license/
 */

class DwzActiveForm extends CActiveForm
{
	public function textArea($model,$attribute,$htmlOptions=array())
	{
		/**
		* 增加ckeditor编辑器渲染
		* $htmlOptions['ckeditor'] == true 时 加载ckeditor
		* $htmlOptions['ckfinder'] == true 时 加载ckfinder
		*/
		if(isset($htmlOptions['ckeditor']) AND $htmlOptions['ckeditor'] == true)
		{
			$modelClass = get_class($model);
			$id = "{$modelClass}_{$attribute}_{$model->primaryKey}";
			$htmlOptions['id'] = $id;
		
			$root = Yii::getPathOfAlias('webroot');
			$ckeditor_file = $root.'/ckeditor/ckeditor.php';
			include($ckeditor_file);
			$CKEditor = new CKEditor();
			$CKEditor->basePath = Yii::app()->getBaseUrl().'/ckeditor/';
			
			if(isset($htmlOptions['ckfinder']) AND $htmlOptions['ckfinder'] == true)
			{
				$ckfinder_file = $root.'/ckfinder/ckfinder.php';
				include($ckfinder_file);
				$CKFinder = new CKFinder();
				$CKFinder->BasePath = Yii::app()->getBaseUrl().'/ckfinder/'; // Note: BasePath property in CKFinder class starts with capital letter
				$CKFinder->SetupCKEditorObject($CKEditor);
			}
			
			$CKEditor->textareaAttributes = $htmlOptions;
			$CKEditor->replace($id);
			
		}

		//$this->checkValidation($model,$attribute,$htmlOptions);
		return parent::textArea($model,$attribute,$htmlOptions);
	}

	public function textField($model,$attribute,$htmlOptions=array())
	{
		/**
		* 增加ckfinder文件查看器渲染
		* $htmlOptions['ckfinder'] == true 时 加载ckfinder
		*/
		if(isset($htmlOptions['ckfinder']) AND $htmlOptions['ckfinder'] == true)
		{
			$buttonId = "{$model->modelClass}_{$attribute}_{$model->primaryKey}";
			$htmlOptions['id'] = $buttonId ;
			
			$htmlOptions['onclick'] = "BrowseServer( 'Images:/', $buttonId );" ;
		}

		//$this->checkValidation($model,$attribute,$htmlOptions);
		return parent::textField($model,$attribute,$htmlOptions);
	}	
}
